package com.my.test.design.factory;


public class Factory {

    public Product createProduct1(String type){
        Product p = null;
        if ("a".equals(type)){
            p = new ProductA();
        } else if ("b".equals(type)){
            p = new ProductB();
        }
        return p;
    }

    public Product createProduct2(Class clazz) throws IllegalAccessException, InstantiationException {

        return (Product)clazz.newInstance();
    }


    public Product createProduct3(Class<? extends Product> clazz) throws IllegalAccessException, InstantiationException {
        return clazz.newInstance();
    }

    public <T> T createProduct4(Class<T> clazz) throws IllegalAccessException, InstantiationException {
        return clazz.newInstance();
    }

}
